// pages/orderTraceability/traceabilitydetail.js
var app = getApp();
var rootDocment = app.globalData.postUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    goodsType: '',
    currentID: '',
    steps: [],
    stepsState: '',
    sendType: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    that.setData({
      currentID: options.id,
      goodsType: options.goodsType
    });
  },
  //初始化详情
  setDetailData: function () {
    var that = this;
    var paraArr = new Array();
    paraArr['id'] = that.data.currentID;
    paraArr['user_id'] = that.data.userInfo.userID;
    paraArr['type'] = that.data.goodsType;
    // paraArr['type'] = 2;
    var sign = app.signature(paraArr);
    wx.request({
      url: rootDocment + '/api/data_grid/traceability',
      data: {
        user_id: paraArr['user_id'],
        type: paraArr['type'],
        order_sn: paraArr['id'],
        // sign: sign
      },
      method: 'GET',
      header: {},
      success: function (res) {
        console.log(res.data);
        let arr = []
        let stepsState = '--'
        if (res.data.express&&res.data.express.content) {
          if (res.data.express.status == 1 && res.data.express.ischeck == 0) {
            stepsState ='运输中'
          }
          if (res.data.express.status == 3 && res.data.express.ischeck == 1) {
            stepsState ='已签收'
          }
          if (res.data.express.status == 0 && res.data.express.ischeck == 0) {
            stepsState ='待揽收'
          }
          
          // res.data.express[0].status
          //  status=1 运输中 
          //  ischeck=1  status=3 已签收
          //  express=[] 待揽收

          res.data.express.content.forEach(element => {
            arr.push({
              text: element.status,
              desc: element.time
            })
          });
          // res.data.express.forEach(element => {
          //   arr.push({
          //     text: element.context,
          //     desc: element.ftime
          //   })
          // });
        }

        res.data.nu=res.data.express.num
        
        that.setData({
          detail: res.data,
          steps: arr,
          stepsState: stepsState
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (opt) {
    var that = this
    //用户授权登录
    app.login(function (userInfo) {
      that.setData({
        userInfo: userInfo
      });
      console.log(userInfo);
      that.setDetailData();
    });
  },

  onSendState() {
    console.log(1111);
    let type = this.data.sendType
    this.setData({
      sendType: !type
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})